package com.ethannhu.todaynews.component.login

import androidx.lifecycle.ViewModelProvider
import androidx.viewbinding.ViewBinding
import com.drake.channel.receiveEvent
import com.ethannhu.todaynews.AppContext
import com.ethannhu.todaynews.activity.BaseTitleActivity
import com.ethannhu.todaynews.component.register.RegisterViewModel


/**
 * 登录通用界面
 */
open class BaseLoginActivity<VB : ViewBinding> : BaseTitleActivity<VB>() {
    lateinit var loginViewModel: LoginViewModel

    override fun initData() {
        super.initData()
        loginViewModel = ViewModelProvider(this)[LoginViewModel::class.java]
        initViewModel(loginViewModel)


        loginViewModel.success.observe(this) {
            //成功了

            //执行登录操作
            AppContext.instance.onLogin()
        }


        receiveEvent<LoginStatusChangedEvent> {
            finish()
        }

    }

}